package pl.edu.agh.io.gpstracker.server.service.handler;

import net.customware.gwt.dispatch.server.ActionHandlerRegistry;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import pl.edu.agh.io.gpstracker.client.action.FindTrackByUserAction;
import pl.edu.agh.io.gpstracker.client.action.GetLastPositionForTrack;
import pl.edu.agh.io.gpstracker.client.dto.TrackDto;
import pl.edu.agh.io.gpstracker.client.dto.TracksequanceDto;
import pl.edu.agh.io.gpstracker.client.result.CollectionResult;
import pl.edu.agh.io.gpstracker.client.result.ObjectResult;
import pl.edu.agh.io.gpstracker.service.TrackService;

import com.adeoservices.gwt.dispatch.spring.server.handler.SpringActionHandler;

/**
 * 
 * @author wkedzior
 * 
 */
@Component
public class GetLastPositionHandler extends
		SpringActionHandler<GetLastPositionForTrack, ObjectResult<TracksequanceDto>> {

	@Autowired
	private TrackService trackService;

	@Autowired
	public GetLastPositionHandler(ActionHandlerRegistry actionHandlerRegistry) {
		super(actionHandlerRegistry);
	}

	@Override
	public Class<GetLastPositionForTrack> getActionType() {
		return GetLastPositionForTrack.class;
	}

	@Override
	public  ObjectResult<TracksequanceDto> execute(GetLastPositionForTrack action,
			ExecutionContext context) {
		return new ObjectResult<TracksequanceDto>( trackService.getLastPositionForTrack(action.getTrackId()));

	}

	@Override
	public void rollback(GetLastPositionForTrack action,
			ObjectResult<TracksequanceDto> result, ExecutionContext context)
			throws ActionException {
		
	}

	
}
